<?php

namespace System\library\logger\formaters;

use System\InitSystem;
use System\library\logger\IFormater;
use System\library\helper\htmlHelper;
use System\library\Debugger;

/**
 * <b>Class</b> :        Html<br>
 * <b>Fonction</b> :     Permet de formater les logs au format html
 * <br>
 * @version              1.0
 * @author               Dread <dreadlokeur@gmail.com>
 * @license              Licence publique générale GNU http://www.gnu.org/licenses/gpl.html
 * @copyright            Copyright 2011 - MidichloriansPHP and contributors
 * @package              System
 * @subpackage           library\logger\formaters
 * 
 * @see System\library\logger\IFormater
 */
class Html implements IFormater {

    private $_indente = true;
    private $_html;

    public function __construct($indente = true) {
        if (!$indente)
            $this->setIndente($indente);
        $this->_html = new HtmlHelper($indente);
    }

    public function setIndente($bool) {
        if (!is_bool($bool))
            throw new \Exception('Indente param must be a boolean');
        $this->_indente = $bool;
    }

    public function getIndente() {
        return $this->_indente;
    }

    public function getFormaterName() {
        return 'html';
    }

    public function getHeader() {
        $header = $this->_html->getDoctype();
        $header .= $this->_html->getBalise('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => InitSystem::getLanguage()));
        $header .= $this->_html->getHeadHtml('Logger');
        $header .= $this->_html->getBalise('body');
        return $header;
    }

    public function getFooter() {
        $footer = $this->_html->getEndBalise('body');
        $footer .= $this->_html->getEndBalise('html');
        return $footer;
    }

    public function format($logs) {
        if (!is_array($logs))
            throw new \Exception('Expression must an array');

        $format = '';
        foreach ($logs as $log) {
            $format .= $this->_html->getBalise('p');
            if ($log['groupTitle']) {
                $format .= $this->_html->getBalise('h4');
                $format .= $log['message'] . '(' . $log['date'] . ')';
                $format .= $this->_html->getEndBalise('h4');
            } else {
                $format .= $this->_html->getBalise('b');
                $format .= 'Date';
                $format .= $this->_html->getEndBalise('b');
                $format .= $log['date'];
                $format .= $this->_html->getBalise('br');
                $format .= $this->_html->getBalise('b');
                $format .= 'Level';
                $format .= $this->_html->getEndBalise('b');
                $format .= $log['level'];
                $format .= $this->_html->getBalise('br');
                $format .= $this->_html->getBalise('b');
                $format .= 'Message';
                $format .= $this->_html->getEndBalise('b');
                $format .= $log['message'];
            }

            $format .= $this->_html->getEndBalise('p');
        }
        return $format;
    }

    public function indente($expression) {
        //TODO implent this
        return $expression;
    }

}

?>
